<?php	
function send_email($to_email,$to_name, $subject,$message,$arrBcc="",$from_email="",$from_name="",$html=true)
{
    global $config_email,$dbsql,$language,$testmail;
    
	if($to_email=="")
	{
		echo "Empty to email!";
		return false;
	}
	if(empty($config_email))
    {
        @ImportClass('json');
        $config_email   = getConfig('SMTPConfig');
        $config_email   = FJSON::decode($config_email);
    }
    
    $smtp_host      = $config_email->host;
    $smtp_user      = $config_email->user;
    $smtp_pass      = $config_email->pass;
    
    $smtp_name      = $config_email->name;
    
    $send_smtp      = ($config_email->type==1)? true : false;
    $smtp_auth      = ($config_email->auth==1)? true : false;
    $smtp_ssl       = ($config_email->ssl==1)? true : false;
   
    
    @include_once("class.phpmailer.php");
    @include_once("class.smtp.php");
	$mail = new PHPMailer();
	
    if($from_email=="")$from_email  = $smtp_user;
	if($from_name=="")$from_name    = $smtp_name;
    
    
	if($send_smtp==true)$mail->IsSMTP(); // send via SMTP
	if($smtp_ssl===true)$mail->SMTPSecure = "ssl";
	if($smtp_auth===true)$mail->SMTPAuth =true; // turn on SMTP authentication
	
	//$mail->SMTPDebug  = 2; 
	
	$mail->Host = $smtp_host; // SMTP servers
	$mail->Port= ($smtp_port>0)? $smtp_port : 25;
    if($smtp_ssl==true && strpos($smtp_host,'gmail')!==false)
    {
        $mail->Port     = 465;
    }
	
	$mail->Username = $smtp_user; // SMTP username
	$mail->Password = $smtp_pass; // SMTP password
	
	$mail->SetFrom($from_email, $from_name);
	$mail->AddReplyTo($from_email,$from_name);
	
	$mail->AddAddress($to_email,$to_name); 
	
	//add bcc if has:
	if(is_array($arrBcc)==false)$arrBcc=array();
	foreach($arrBcc as $i => $email)
	{
		$mail->AddBCC($email,""); 
	}
	
	$mail->WordWrap = 50; // set word wrap
	$mail->IsHTML($html); // send as HTML
	$mail->CharSet = "UTF-8";
	
	$mail->Subject = $subject;
	$mail->Body = $message;
	$mail->AltBody = "";
	if(!$mail->Send())
	{
	   if($send_smtp==true && $testmail!==true)
       {
            $mail->IsMail();
            if(!$mail->Send())
	        {
	           return false;
            }else
            {
                return true;
            }
       }
       if($testmail)
       {
            $GLOBALS['err']  = $mail->ErrorInfo;
       }
		return false;	
	}
	return true;
} 
?>